#define DEBUG
#include <cstdio>
#define MAXN 50000

using namespace std;

long long sqr(long long a) {
  return a*a;
}

long long getPoint(long long *a, long long *b) {
  return (a[1]-b[1])/(b[0]-a[0]);
}

int main() {
#ifdef DEBUG
  freopen("0.in", "r", stdin);
  freopen("0.out", "w", stdout);
#endif

  static int c[MAXN+1];
  static long long s[MAXN+1], que[MAXN+1][2];
  int n, l;
  scanf("%d %d", &n, &l);
  s[0]=0;
  for (int i=1; i<=n; i++) {
    scanf("%d", c+i);
    s[i]=s[i-1]+c[i];
  }

  int h=1, t=1;
  long long temp[2], f;
  que[1][0]=-2, que[1][1]=1;
  for (int i=1; i<=n; i++) {
    for (; h<t && getPoint(que[h], que[h+1])<s[i]+i-l; h++);
    f=sqr(s[i]+i-l)+que[h][0]*(s[i]+i-l)+que[h][1];
    temp[0]=-2*(s[i]+i+1), temp[1]=sqr(s[i]+i+1)+f;
    for (; h<t && ((temp[0]==que[t][0] && temp[1]<que[t][1]) || (temp[0]!=que[t][0] && getPoint(que[t-1], que[t])>=getPoint(que[t-1], temp))); t--);
    if (temp[0]!=que[t][0] || temp[1]!=que[t][1]) {
      t++;
      que[t][0]=temp[0], que[t][1]=temp[1];
    }
  }
  printf("%lld", f);

  fclose(stdin);
  fclose(stdout);
  return 0;
}
